package frontend.pages.admin.project;

import backend.model.admin.Project;
import backend.service.admin.ProjectService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.ProjectUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;

@MountPath("project")
public class ProjectManagingPage extends AbstractManagingPage<Project> {

	public ProjectManagingPage() {
		super("pages.admin.project.title", "contextualHelp.admin.project.text");
	}

    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.project.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.project.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.project.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new ProjectPanel(panelId, getPageParameters(), new ProjectUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, Project project) {
        getPageParameters().clearNamed();
        return new ProjectPanel(panelId, null, new ProjectUIModel(project));
    }

    @Override
    public List<Project> loadAvailableEntities() {
        ProjectService projectService = TimeTrackingWebApplication.getService(ProjectService.class);
        return projectService.findAllProjects();
    }
}
